﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TextMIS
{
    public partial class frmPERecord : Form
    {

        dbopr ywszbiz = new dbopr();
        sysopr xtbiz = new sysopr();
        //体检疾病相关
        registopr Disease = new registopr();
        //体检登记相关
        registopr Register = new registopr();
        DataTable dt_tjjlmxb = null;//记录明细表
        DataTable dt_jbjlb = null;//疾病记录表
        string str_RegID = "";//体检编号
        string str_Count = "";//体检次数
        string str_zhxm = "";//组合项目
        string str_xh = "";//记录序号
        string str_xb = "%";//性别
        string str_User = "";//历史记录操作员
        string str_xzedit = "";//是否限制录入人修改 1限制 0不限制
        private int index = 0;
        //MachineCode ma = new MachineCode();
        loginBiz loginbiz = new loginBiz();
        public frmPERecord()
        {
            InitializeComponent();
        }
        void DataBind()
        {
            dtp_jcrq.Value = xtbiz.GetServerDate();

            cmb_ks.SelectedValueChanged -= new EventHandler(cmb_ks_SelectedValueChanged);
            cmb_ks.DataSource = ywszbiz.Get_Bran_list();
            cmb_ks.DisplayMember = "Bra_id";
            cmb_ks.ValueMember = "Bra_name";
            cmb_ks.SelectedIndex = -1;
            cmb_ks.SelectedValueChanged += new EventHandler(cmb_ks_SelectedValueChanged);

        }

        void cmb_ks_SelectedValueChanged(object sender, EventArgs e)
        {
            cmb_jcys.SelectedIndex = -1;
            //cmb_jcys.DataSource = tjjgbiz.Get_Xt_YS_dxlr(); //0803修改
            cmb_jcys.DataSource = ywszbiz.Get_Branuser(cmb_ks.SelectedValue.ToString());//原来
            cmb_jcys.DisplayMember = "User_Id";
            cmb_jcys.ValueMember = "User_name";
            //cmb_jcys.Text = Program.username;


        }


        private void frmPERecorfd_Load(object sender, EventArgs e)
        {
            DataBind();
            str_xzedit = xtbiz.GetXtCsz("XzEdit").Trim();//0不做任何限制，1限制，只有录入人可以修改
            dgv_tjjlmxb.Tag = "";

            //string str_wzks = xtbiz.GetXtCsz("wzksid").Trim(); //问诊所在科室
            //if (Program.ksid == str_wzks)
            //{
            //    btn_wz.Enabled = true;
            //}
            //else
            //{
            //    btn_wz.Enabled = false;
            //}

        }

        private void bt_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        void TJDJB_DataBind(string tjbh, string tjcs)
        {

            //通过视图获取登记信息
            //DataTable dt = tjjgbiz.Get_V_TJ_TJDJB(str_tjbh, str_tjcs);
            //txt_Unit.Text = dt.Rows[0]["dwmc"].ToString().Trim();
            //txt_RingNo.Text = dt.Rows[0]["djlsh"].ToString().Trim();
            //txt_RegId.Text = dt.Rows[0]["tjbh"].ToString().Trim();
            //txt_Count.Text = dt.Rows[0]["tjcs"].ToString().Trim();
            //txt_Name.Text = dt.Rows[0]["xm"].ToString().Trim();
            //txt_Sex.Text = dt.Rows[0]["xb"].ToString().Trim();
            //txt_Age.Text = dt.Rows[0]["nl"].ToString().Trim();
            //txt_whys.Text = dt.Rows[0]["whysmc"].ToString().Trim();
            //string sfzh = dt.Rows[0]["sfzh"].ToString().Trim();
            ////身份证号月日加密处理
            //if (sfzh != "")  //510132198010076618    511204761018072
            //{
            //    if (sfzh.Length == 18)
            //    {
            //        sfzh = sfzh.Substring(0, 8) + "******" + sfzh.Substring(14, 4);
            //    }
            //    else   //15位
            //    {
            //        sfzh = sfzh.Substring(0, 6) + "******" + sfzh.Substring(12, 3);
            //    }
            //}
            //txt_CardID.Text = sfzh;
            //str_xb = dt.Rows[0]["xbcode"].ToString().Trim();//性别代码
                                                            //头像处理----------------------------------------------------------------------

            try
            {
                //MemoryStream buf = new MemoryStream((byte[])dt.Rows[0]["picture"]);
                //Image showimage = Image.FromStream(buf, true);
                //pictureBox1.Image = showimage;
            }
            catch
            {
                pictureBox1.Image = null;
            }

            this.ActiveControl = cmb_ks;
            if (object.Equals(null, cmb_ks.SelectedValue)) return;
            TJJLB_DataBind(tjbh, tjcs, cmb_ks.SelectedValue.ToString().Trim());//绑定体检记录表
        }

        void TJJLB_DataBind(string tjbh, string tjcs, string ksid)//绑定体检记录表
        {
            dgv_tjjlb.DataSource = Disease.Get_TJ_TJJLB(tjbh, tjcs, ksid);

            if (!object.Equals(null, dt_tjjlmxb)) dt_tjjlmxb.Rows.Clear();//先清除，在绑定

            if (object.Equals(null, dgv_tjjlb.CurrentRow)) return;

            str_zhxm = dgv_tjjlb.CurrentRow.Cells["zhxm"].Value.ToString().Trim();//组合项目编号
            str_xh = dgv_tjjlb.CurrentRow.Cells["xh"].Value.ToString().Trim();//记录表序号

            rtb_Brife.Text = "";
            DataTable dt = Disease.Get_TJ_TJJLB(str_RegID, str_Count, str_xh, str_zhxm);
            //判断是否限制同一个医生进行修改的-----------------------------------------------------------------------------
            try
            {
                dtp_jcrq.Value = Convert.ToDateTime(dt.Rows[0]["jcrq"]);
                cmb_jcys.SelectedValue = dt.Rows[0]["jcys"].ToString().Trim();
                rtb_Brife.Text = dt.Rows[0]["xj"].ToString().Trim();
                str_User = dt.Rows[0]["czy"].ToString().Trim();//历史录入过的操作员-------------------------------------------------

            }
            catch { }

            JLMXB_DataBind(dgv_tjjlb.CurrentRow);
            JBJLB_DataBind(str_RegID, str_Count, str_zhxm);//绑定疾病记录表

            foreach (DataGridViewRow dgr in dgv_tjjlb.Rows)//改变背景颜色
            {
                if (dgr.Cells["isover"].Value.ToString().Trim() == "1")
                {
                    dgr.DefaultCellStyle.BackColor = Color.Green;
                }
            }
        }
        //快速检索——鼠标右键
        private void txt_ksjs_MouseDown(object sender, MouseEventArgs e)
        {
            //if (e.Button == MouseButtons.Right)
            //{
            //    Form_tycx frm = new Form_tycx("");
            //    if (frm.ShowDialog() == DialogResult.OK)
            //    {
            //        str_RegID = frm.str_tjbh;
            //        str_Count = frm.str_tjcs;
            //        if (frm.str_sumover == "2")
            //        {
            //            if (DialogResult.No == MessageBox.Show("该人员已经总检，是否查看记录？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1))
            //            {
            //                return;
            //            }
            //        }
            //        TJDJB_DataBind(str_RegID, str_Count);
            //    }
            //}
        }

        private void txt_ksjs_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                if (txt_Search.Text.Trim() == "")
                {
                    MessageBox.Show("请填写快速检索值！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.ActiveControl = txt_Search;
                    return;
                }
                //Reg_Id,Count,PE_stau,sfbz
                DataTable dt = Disease.Get_RetrReg(txt_Search.Text.Trim());
                if (dt.Rows.Count > 0)
                {
                    str_RegID = dt.Rows[0]["Reg_Id"].ToString().Trim();
                    str_Count = dt.Rows[0]["Count"].ToString().Trim();
                    string str_sumover = dt.Rows[0]["PE_stau"].ToString().Trim();
                    if (str_sumover == "2")
                    {
                        if (DialogResult.No == MessageBox.Show("该人员已经总检，是否继续查看记录？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1))
                        {
                            txt_Search.Text = "";
                            return;
                        }
                    }

                    #region  收费检查
                    string str_sfbz = dt.Rows[0]["sfbz"].ToString().Trim(); //必须收费标志
                    string str_bzsfxz = xtbiz.GetXtCsz("bzsfxz");//办证收费流程限制
                    if (str_bzsfxz == "1" && str_sfbz == "1")   //限制
                    {
                        int sl = Register.TjSfCx(str_RegID, str_Count);
                        if (sl <= 0)    //未收费
                        {
                            MessageBox.Show("本单位进行了财务流程控制，请先交费!", "提示");
                            return;
                        }
                    }
                    #endregion

                    TJDJB_DataBind(str_RegID, str_Count);


                }
                else
                {
                    MessageBox.Show("没有检索到记录，请检查检索值！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                txt_Search.Text = "";
            }
        }

        private void cmb_ks_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (str_RegID == "" || str_Count == "") return;
            TJJLB_DataBind(str_RegID, str_Count, cmb_ks.SelectedValue.ToString().Trim());
        }

        private void bt_edit_Click(object sender, EventArgs e)
        {
            //非本人不能修改
            if (str_xzedit == "1")
            {
                if (str_User != Program.userid)
                {
                    MessageBox.Show("不能修改其他操作人员录入的数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    #region 日志记录
                    loginbiz.WriteLog(this.Name.Trim(), "【" + Program.username + "】" + "在电脑上尝试非法修改" + str_RegID + "的体检报告!IP：" + Program.hostip, Program.username);
                    #endregion
                    return;
                }
            }
            bt_Brife.Enabled = true;
            bt_save.Enabled = true;
            dgv_jbjlb.Enabled = true;
            rtb_Brife.Enabled = true;
            dgv_tjjlmxb.ReadOnly = false;
            #region 日志记录
            loginbiz.WriteLog(this.Name.Trim(), "【" + Program.username + "】" + "在电脑上修改" + str_RegID + "的体检报告!IP：" + Program.hostip, Program.username);
            #endregion
        }
        //体检记录明细表
        void JLMXB_DataBind(DataGridViewRow dgr)
        {
            str_zhxm = dgr.Cells["zhxm"].Value.ToString().Trim();
            str_xh = dgr.Cells["xh"].Value.ToString().Trim();
            string str_isover = dgr.Cells["isover"].Value.ToString().Trim();
            if (str_isover == "1")//表示已经保存过-------------默认不允许修改---------------------------------
            {
                bt_Brife.Enabled = false;
                bt_save.Enabled = false;
                dgv_jbjlb.Enabled = false;
                rtb_Brife.Enabled = false;
                dgv_tjjlmxb.ReadOnly = true;
            }
            else
            {
                bt_Brife.Enabled = true;
                bt_save.Enabled = true;
                dgv_jbjlb.Enabled = true;
                rtb_Brife.Enabled = true;
                dgv_tjjlmxb.ReadOnly = false;
            }
            //项目类型
            string str_xmlx = dgr.Cells["xmlx"].Value.ToString().Trim();//0检验科 1医生检查 2功能检查
            //通过序号和组合项目 获取体检记录明细
            dt_tjjlmxb = Disease.Get_TJ_TJJLMXB(str_xh, str_zhxm);//---------------------
            dgv_tjjlmxb.DataSource = dt_tjjlmxb;
            dgv_tjjlmxb.Tag = str_xmlx;//Tag保存项目类型值-----------------------------------------------------------------------------------
            if (str_xmlx == "0")
            {
                dgv_tjjlmxb.Columns["tjjlmxb_jg"].Width = 70;
                dgv_tjjlmxb.Columns["tjjlmxb_dw"].Visible = true;
                dgv_tjjlmxb.Columns["tjjlmxb_ckxx"].Visible = true;
                dgv_tjjlmxb.Columns["tjjlmxb_cksx"].Visible = true;
                dgv_tjjlmxb.Columns["spy"].Visible = true;
                dgv_tjjlmxb.Columns["xpy"].Visible = true;
            }
            if (str_xmlx == "1")
            {
                dgv_tjjlmxb.Columns["tjjlmxb_jg"].Width = 200;
                dgv_tjjlmxb.Columns["tjjlmxb_dw"].Visible = true;
                dgv_tjjlmxb.Columns["tjjlmxb_ckxx"].Visible = false;
                dgv_tjjlmxb.Columns["tjjlmxb_cksx"].Visible = false;

                dgv_tjjlmxb.Columns["spy"].Visible = false;
                dgv_tjjlmxb.Columns["xpy"].Visible = false;
            }
            if (str_xmlx == "2")
            {
                dgv_tjjlmxb.Columns["tjjlmxb_jg"].Width = 300;
                dgv_tjjlmxb.Columns["tjjlmxb_dw"].Visible = false;
                dgv_tjjlmxb.Columns["tjjlmxb_ckxx"].Visible = false;
                dgv_tjjlmxb.Columns["tjjlmxb_cksx"].Visible = false;
                dgv_tjjlmxb.Columns["spy"].Visible = false;
                dgv_tjjlmxb.Columns["xpy"].Visible = false;
            }
            //1初始化参考值 2获取该项疾病记录 3异常情况，结果以红色字体显示
            foreach (DataGridViewRow dgrow in dgv_tjjlmxb.Rows)
            {
                //获取疾病历史记录
                string str_tjlx = dgrow.Cells["tjjlmxb_tjlx"].Value.ToString().Trim();
                string str_tjxm = dgrow.Cells["tjjlmxb_tjxm"].Value.ToString().Trim();
                dgrow.Cells["tjjlmxb_keyword"].Value = Disease.Get_tj_jbjlb_jbbh(str_RegID, str_Count, str_tjlx, str_zhxm, str_tjxm);

                //检验科获取参考值
                if (str_xmlx == "0")
                {
                    int nl = 0;
                    try
                    {
                        nl = Convert.ToInt32(txt_Age.Text.Trim());
                    }
                    catch
                    {
                    }

                    //获取参考值
                    DataTable dtCkz = Disease.Get_pro_get_ckz(str_tjlx, str_tjxm, str_xb, nl, "");//暂不处理单项录入
                    if (dtCkz.Rows.Count == 0)
                    {
                        continue;
                    }
                    string str_ckz = dtCkz.Rows[0]["ckz"].ToString().Trim();
                    if (str_ckz == "") continue;//获取值为空跳过，设置有问题

                    dgrow.Cells["tjjlmxb_ckxx"].Value = str_ckz.Split('—')[0];
                    dgrow.Cells["tjjlmxb_cksx"].Value = str_ckz.Split('—')[1];
                    dgrow.Cells["tjjlmxb_ckz"].Value = str_ckz;
                    dgrow.Cells["spy"].Value = dtCkz.Rows[0]["spy"].ToString().Trim();
                    dgrow.Cells["xpy"].Value = dtCkz.Rows[0]["xpy"].ToString().Trim();

                    //string str_ckz = tjjgbiz.Get_pro_get_ckz(str_tjlx, str_tjxm, str_xb, nl);
                    //if (str_ckz == "") continue;//获取值为空跳过，设置有问题

                    //dgrow.Cells["tjjlmxb_ckxx"].Value = str_ckz.Split('-')[0];
                    //dgrow.Cells["tjjlmxb_cksx"].Value = str_ckz.Split('-')[1];
                    //dgrow.Cells["tjjlmxb_ckz"].Value = str_ckz;
                }
                //异常情况，结果以红色字体显示
                string str_sfyx = dgrow.Cells["tjjlmxb_sfyx"].Value.ToString().Trim();
                if (str_sfyx == "1")
                {
                    dgrow.Cells["tjjlmxb_jg"].Style.ForeColor = Color.Red;
                }
            }
            //////////////////////////////////////////////////////////////

        }

        void JBJLB_DataBind(string tjbh, string tjcs, string zhxmbh)
        {
            dt_jbjlb = Disease.Get_tj_jbjlb(tjbh, tjcs, zhxmbh);
            dgv_jbjlb.DataSource = dt_jbjlb;

        }

        private void dgv_tjjlmxb_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right && e.ColumnIndex == 3)
            {
                if (dgv_tjjlmxb.ReadOnly) return;
                if (object.Equals(null, dgv_tjjlmxb.CurrentRow)) return;
                DataGridViewRow dgr = dgv_tjjlmxb.CurrentRow;
                string str_tjlx = dgr.Cells["tjjlmxb_tjlx"].Value.ToString().Trim();
                string str_tjxm = dgr.Cells["tjjlmxb_tjxm"].Value.ToString().Trim();
                string str_mc = dgr.Cells["tjjlmxb_mc"].Value.ToString().Trim();
                string str_jg = dgr.Cells["tjjlmxb_jg"].Value.ToString().Trim();
                //参考值界面
                //Form_tjjgckz frm = new Form_tjjgckz(str_jg, str_tjlx, str_tjxm, str_mc);
                //if (frm.ShowDialog() == DialogResult.OK)
                //{
                //    dgr.Cells["tjjlmxb_jg"].Value = frm.str_jg;
                //    dgr.Cells["tjjlmxb_sfyx"].Value = frm.str_sfyx;
                //    dgr.Cells["tjjlmxb_jrxj"].Value = frm.str_into_xj;
                //    dgr.Cells["tjjlmxb_mcjrxj"].Value = frm.str_mcjrxj;
                //    dgr.Cells["tjjlmxb_keyword"].Value = frm.str_keyword;//对应诊断
                //    if (frm.str_sfyx == "1")
                //    {
                //        dgr.Cells["tjjlmxb_jg"].Style.ForeColor = Color.Red;
                //    }
                //    else
                //    {
                //        dgr.Cells["tjjlmxb_jg"].Style.ForeColor = dgr.Cells[0].Style.ForeColor;
                //    }
                //    if (!frm.bool_check)//表示没有选择体检结果，而是手工输入值后返回
                //    {
                //        Get_CellCharge_JG(dgr);
                //    }
                //}
            }
        }

        private void dgv_tjjlmxb_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            //if (e.ColumnIndex == 1)
            //{
            //    if (object.Equals(null, dgv_tjjlmxb.CurrentRow)) return;
            //    DataGridViewRow dgr = dgv_tjjlmxb.CurrentRow;
            //    dgv_tjjlmxb.CurrentCell.Value = dgr.Cells["tjjlmxb_zcjg"].Value;
            //}
            if (e.ColumnIndex == 3 && dgv_tjjlmxb.ReadOnly)
            {
                MessageBox.Show("请点击修改按钮！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.ActiveControl = bt_edit;
                return;
            }
        }

        void Get_CellCharge_JG(DataGridViewRow dgr)
        {
            string str_zhxm = dgr.Cells["tjjlmxb_tjzhxm"].Value.ToString().Trim();//组合项目
            if (Disease.Exists_SGTZXY(str_zhxm) > 0) return;//判断是否为肥胖，血压,不参与阳性判断

            string str_mc = dgr.Cells["tjjlmxb_mc"].Value.ToString().Trim();
            string str_jg = dgr.Cells["tjjlmxb_jg"].Value.ToString().Trim();
            string str_zcjg = dgr.Cells["tjjlmxb_zcjg"].Value.ToString().Trim();
            string str_tjlx = dgr.Cells["tjjlmxb_tjlx"].Value.ToString().Trim();
            string str_tjxm = dgr.Cells["tjjlmxb_tjxm"].Value.ToString().Trim();
            string str_cksx = dgr.Cells["tjjlmxb_cksx"].Value.ToString().Trim();//参考上限
            string str_ckxx = dgr.Cells["tjjlmxb_ckxx"].Value.ToString().Trim();//参考下限
            string spy = "";
            string xpy = "";
            try
            {
                spy = dgr.Cells["spy"].Value.ToString().Trim();
                xpy = dgr.Cells["xpy"].Value.ToString().Trim();
            }
            catch
            {

            }

            if (spy == "") spy = "0";
            if (xpy == "") xpy = "0";

            if (dgv_tjjlmxb.Tag.ToString().Trim() == "0")//检验科
            {
                double dou_jg = 0.00;//结果
                double dou_cksx = 0.00;//参考上限
                double dou_ckxx = 0.00;//参考下限
                bool converted = false;//结果是否成功转换
                int nl = 0;//年龄
                try
                {
                    dou_jg = Convert.ToDouble(str_jg);
                    converted = true;
                    dou_cksx = Convert.ToDouble(str_cksx) + Convert.ToDouble(spy);
                    dou_ckxx = Convert.ToDouble(str_ckxx) - Convert.ToDouble(xpy);
                    nl = Convert.ToInt32(txt_Age.Text.Trim());
                }
                catch
                {
                }
                if (dou_jg < dou_ckxx || dou_jg > dou_cksx)//不在正常范围
                {
                    string str_ckzjg = Disease.Get_pro_get_ckz_jg(str_tjlx, str_tjxm, str_xb, nl, dou_jg, "");//暂时没处理

                    dgr.Cells["tjjlmxb_ts"].Value = str_ckzjg.Split('|')[0];
                    dgr.Cells["tjjlmxb_keyword"].Value = str_ckzjg.Split('|')[1];

                    dgr.Cells["tjjlmxb_sfyx"].Value = "1";
                    dgr.Cells["tjjlmxb_jrxj"].Value = "1";
                    dgr.Cells["tjjlmxb_mcjrxj"].Value = "1";
                    dgr.Cells["tjjlmxb_jg"].Style.ForeColor = Color.Red;
                }
                else if (dou_jg <= dou_cksx && dou_jg >= dou_ckxx && converted)//正常范围,输入的是数字结果
                {
                    dgr.Cells["tjjlmxb_ts"].Value = "";
                    dgr.Cells["tjjlmxb_keyword"].Value = "";

                    dgr.Cells["tjjlmxb_sfyx"].Value = "0";
                    dgr.Cells["tjjlmxb_jrxj"].Value = "0";
                    dgr.Cells["tjjlmxb_mcjrxj"].Value = "0";
                    dgr.Cells["tjjlmxb_jg"].Style.ForeColor = dgr.Cells[0].Style.ForeColor;
                }
                else
                {
                    if (str_jg != str_zcjg)
                    {
                        dgr.Cells["tjjlmxb_ts"].Value = "";
                        dgr.Cells["tjjlmxb_sfyx"].Value = "1";
                        dgr.Cells["tjjlmxb_jrxj"].Value = "1";
                        dgr.Cells["tjjlmxb_mcjrxj"].Value = "1";
                        dgr.Cells["tjjlmxb_jg"].Style.ForeColor = Color.Red;

                        string str_keyword = Disease.Get_tj_suggestion_jbbh(str_tjlx, str_jg);//当结果为阳性时，强制字符匹配诊断->名称不进入小结
                        if (str_keyword == "")
                        {
                            str_keyword = Disease.Get_tj_suggestion_jbbh(str_tjlx, str_mc + str_jg);//当结果为阳性时，强制字符匹配诊断->名称进入小结
                        }
                        dgr.Cells["tjjlmxb_keyword"].Value = str_keyword;
                    }
                    else
                    {
                        dgr.Cells["tjjlmxb_ts"].Value = "";
                        dgr.Cells["tjjlmxb_sfyx"].Value = "0";
                        dgr.Cells["tjjlmxb_jrxj"].Value = "0";
                        dgr.Cells["tjjlmxb_mcjrxj"].Value = "0";
                        dgr.Cells["tjjlmxb_jg"].Style.ForeColor = dgr.Cells[0].Style.ForeColor;
                        dgr.Cells["tjjlmxb_keyword"].Value = "";
                    }
                }
            }
            else//医生检查科室和功能检查科室
            {
                if (str_jg != str_zcjg)
                {
                    dgr.Cells["tjjlmxb_sfyx"].Value = "1";
                    dgr.Cells["tjjlmxb_jrxj"].Value = "1";
                    dgr.Cells["tjjlmxb_mcjrxj"].Value = "1";
                    dgr.Cells["tjjlmxb_jg"].Style.ForeColor = Color.Red;

                    string str_keyword = Disease.Get_tj_suggestion_jbbh(str_tjlx, str_jg);//当结果为阳性时，强制字符匹配诊断->名称不进入小结

                    if (str_keyword == "")
                    {
                        str_keyword = Disease.Get_tj_suggestion_jbbh(str_tjlx, str_mc + str_jg);//当结果为阳性时，强制字符匹配诊断->名称进入小结
                    }

                    dgr.Cells["tjjlmxb_keyword"].Value = str_keyword;
                }
                else
                {
                    dgr.Cells["tjjlmxb_sfyx"].Value = "0";
                    dgr.Cells["tjjlmxb_jrxj"].Value = "0";
                    dgr.Cells["tjjlmxb_mcjrxj"].Value = "0";
                    dgr.Cells["tjjlmxb_jg"].Style.ForeColor = dgr.Cells[0].Style.ForeColor;
                    dgr.Cells["tjjlmxb_keyword"].Value = "";
                }
            }
        }
        private void dgv_tjjlmxb_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (object.Equals(null, dgv_tjjlmxb.CurrentRow)) return;
            DataGridViewRow dgr = dgv_tjjlmxb.CurrentRow;

            string str_tlzhxmid = xtbiz.GetXtCsz("tlzhxmid").Trim();

            //听力不进入小结
            //if (e.ColumnIndex == 3)
            //{
            //    dgr.Cells[3].Value = new Common.Common().CharConverter(dgr.Cells[3].Value.ToString().Trim());
            //    if (dgr.Cells["tjjlmxb_tjzhxm"].Value.ToString().Trim() == str_tlzhxmid)//如果是听力组合项目，不进入小结
            //    {
            //        return;
            //    }
            //    Get_CellCharge_JG(dgr);
            //}
        }

        private void bt_save_Click(object sender, EventArgs e)
        {
            if (str_RegID == "" || str_Count == "") return;
            if (dgv_tjjlmxb.Rows.Count == 0) return;
            dt_tjjlmxb.AcceptChanges();
            if (object.Equals(null, cmb_jcys.SelectedValue))
            {
                MessageBox.Show("请选择检查医生！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.ActiveControl = cmb_jcys;
                return;
            }
            if (rtb_Brife.Text.Trim() == "")
            {
                MessageBox.Show("请先生成小结！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.ActiveControl = rtb_Brife;
                return;
            }
            ////////////////////////////////////////////////////////////////////////
            //if (cmb_jcys.SelectedValue.ToString().Trim() != Program.userid.Trim())
            //{
            //    MessageBox.Show("不能修改其它科室结果！");
            //    return;
            //}
            ///////////////////////////////////////////////////////////////////////


            string str_tjlx = dgv_tjjlmxb.Rows[0].Cells["tjjlmxb_tjlx"].Value.ToString().Trim();
            registopr tjjgbiz1 = new registopr();
            tjjgbiz1.str_Delete_tj_jbjlb(str_RegID, str_Count, str_zhxm);
            tjjgbiz1.str_Update_tj_tjjlb(str_RegID, str_Count, str_xh, str_zhxm, "1", dtp_jcrq.Value.ToString(), cmb_jcys.SelectedValue.ToString().Trim(), rtb_Brife.Text.Trim(), Program.userid);
            foreach (DataGridViewRow dgr in dgv_tjjlmxb.Rows)
            {
                string str_jg = dgr.Cells["tjjlmxb_jg"].Value.ToString().Trim();
                string str_tjxm = dgr.Cells["tjjlmxb_tjxm"].Value.ToString().Trim();
                string str_tjzhxm = dgr.Cells["tjjlmxb_tjzhxm"].Value.ToString().Trim();//组合项目编号
                string str_sfyx = dgr.Cells["tjjlmxb_sfyx"].Value.ToString().Trim();
                string str_jrxj = dgr.Cells["tjjlmxb_jrxj"].Value.ToString().Trim();
                string str_mcjrxj = dgr.Cells["tjjlmxb_mcjrxj"].Value.ToString().Trim();
                string str_dw = dgr.Cells["tjjlmxb_dw"].Value.ToString().Trim();
                string str_ckz = dgr.Cells["tjjlmxb_ckz"].Value.ToString().Trim();
                string str_ts = dgr.Cells["tjjlmxb_ts"].Value.ToString().Trim();

                tjjgbiz1.str_Update_tj_tjjlmxb(str_xh, str_tjxm, str_jg, str_tjzhxm, str_tjlx, dtp_jcrq.Value.ToString(), cmb_jcys.SelectedValue.ToString().Trim(),
                    str_jrxj, str_mcjrxj, str_sfyx, str_dw, str_ckz, str_ts);
            }
            foreach (DataGridViewRow dgr in dgv_jbjlb.Rows)
            {
                //疾病记录表
                string str_jbxh = xtbiz.GetId("jbjlid", 1);
                string str_jbbh = dgr.Cells["jb_jbbh"].Value.ToString().Trim();
                string str_jbmc = dgr.Cells["jb_jbmc"].Value.ToString().Trim();
                string str_tjxmbh = dgr.Cells["jb_tjxmbh"].Value.ToString().Trim();
                tjjgbiz1.str_Insert_tj_jbjlb(str_jbxh, str_RegID, str_Count, txt_RingNo.Text.Trim(), str_tjlx, str_zhxm, str_tjxmbh, str_jbbh, str_jbmc, cmb_jcys.SelectedValue.ToString().Trim());
            }
            tjjgbiz1.str_Update_tj_tjdjb(str_RegID, str_Count, "1");
            tjjgbiz1.Exec_ArryList();
            MessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            dgv_tjjlb.CurrentRow.DefaultCellStyle.BackColor = Color.Green;
            dgv_tjjlb.CurrentRow.Cells["isover"].Value = "1";

            #region 日志记录
            loginbiz.WriteLog(this.Name.Trim(), "【" + Program.username + "】" + "在电脑上保存了" + str_RegID + "的单项体检结果!IP：" + Program.hostip, Program.username);
            #endregion

            try
            {
                dgv_tjjlb.CurrentCell = dgv_tjjlb.Rows[dgv_tjjlb.CurrentRow.Index + 1].Cells[0];
            }
            catch { }
            //JLMXB_DataBind(dgv_tjjlb.CurrentRow);
            //JBJLB_DataBind(str_tjbh, str_tjcs, str_zhxm);//绑定疾病记录表
        }

        /// <summary>
        /// 听力计算
        /// </summary>
        void Tljs()
        {
            string left500 = dgv_tjjlmxb.Rows[0].Cells["tjjlmxb_jg"].Value.ToString().Trim();
            string right500 = dgv_tjjlmxb.Rows[1].Cells["tjjlmxb_jg"].Value.ToString().Trim();
            string left1000 = dgv_tjjlmxb.Rows[2].Cells["tjjlmxb_jg"].Value.ToString().Trim();
            string right1000 = dgv_tjjlmxb.Rows[3].Cells["tjjlmxb_jg"].Value.ToString().Trim();
            string left2000 = dgv_tjjlmxb.Rows[4].Cells["tjjlmxb_jg"].Value.ToString().Trim();
            string right2000 = dgv_tjjlmxb.Rows[5].Cells["tjjlmxb_jg"].Value.ToString().Trim();
            string left3000 = dgv_tjjlmxb.Rows[6].Cells["tjjlmxb_jg"].Value.ToString().Trim();
            string right3000 = dgv_tjjlmxb.Rows[7].Cells["tjjlmxb_jg"].Value.ToString().Trim();
            string left4000 = dgv_tjjlmxb.Rows[8].Cells["tjjlmxb_jg"].Value.ToString().Trim();
            string right4000 = dgv_tjjlmxb.Rows[9].Cells["tjjlmxb_jg"].Value.ToString().Trim();
            string left6000 = dgv_tjjlmxb.Rows[10].Cells["tjjlmxb_jg"].Value.ToString().Trim();
            string right6000 = dgv_tjjlmxb.Rows[11].Cells["tjjlmxb_jg"].Value.ToString().Trim();

            string nl = txt_Age.Text.Trim();
            if (nl == "")
            {
                MessageBox.Show("年龄不能为空！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string xb = txt_Sex.Text.Trim();

            if (left500 == "")
            {
                MessageBox.Show("左耳500HZ不能为空！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (right500 == "")
            {
                MessageBox.Show("右耳500HZ不能为空！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (left1000 == "")
            {
                MessageBox.Show("左耳1000HZ不能为空！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (right1000 == "")
            {
                MessageBox.Show("右耳1000HZ不能为空！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (left3000 == "")
            {
                MessageBox.Show("左耳3000HZ不能为空！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (right3000 == "")
            {
                MessageBox.Show("右耳3000HZ不能为空！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (left4000 == "")
            {
                MessageBox.Show("左耳4000HZ不能为空！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (right4000 == "")
            {
                MessageBox.Show("右耳4000HZ不能为空！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (left6000 == "")
            {
                MessageBox.Show("左耳6000HZ不能为空！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (right6000 == "")
            {
                MessageBox.Show("右耳6000HZ不能为空！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            left500 = xtbiz.GetTjjdz(nl, xb, 500, left500);
            right500 = xtbiz.GetTjjdz(nl, xb, 500, right500);
            left1000 = xtbiz.GetTjjdz(nl, xb, 1000, left1000);
            right1000 = xtbiz.GetTjjdz(nl, xb, 1000, right1000);
            left2000 = xtbiz.GetTjjdz(nl, xb, 2000, left2000);
            right2000 = xtbiz.GetTjjdz(nl, xb, 2000, right2000);
            left3000 = xtbiz.GetTjjdz(nl, xb, 3000, left3000);
            right3000 = xtbiz.GetTjjdz(nl, xb, 3000, right3000);
            left4000 = xtbiz.GetTjjdz(nl, xb, 4000, left4000);
            right4000 = xtbiz.GetTjjdz(nl, xb, 4000, right4000);
            left6000 = xtbiz.GetTjjdz(nl, xb, 6000, left6000);
            right6000 = xtbiz.GetTjjdz(nl, xb, 6000, right6000);

            decimal l5, l1, l2, se = 0, de = 0;
            l5 = Math.Min(Convert.ToDecimal(left500), Convert.ToDecimal(right500));
            l1 = Math.Min(Convert.ToDecimal(left1000), Convert.ToDecimal(right1000));
            if (left2000 == "" || right2000 == "")//2000没做
            {
                de = (l5 + l1) / 2;
            }
            else
            {
                l2 = Math.Min(Convert.ToDecimal(left2000), Convert.ToDecimal(right2000));
                de = (l5 + l1 + l2) / 3;
            }

            se = (Convert.ToDecimal(left3000) + Convert.ToDecimal(right3000) + Convert.ToDecimal(left4000) + Convert.ToDecimal(right4000)
                + Convert.ToDecimal(left6000) + Convert.ToDecimal(right6000)) / 6;//双耳高频

            dgv_tjjlmxb.Rows[13].Cells["tjjlmxb_jg"].Value = de.ToString("0.00");
            dgv_tjjlmxb.Rows[12].Cells["tjjlmxb_jg"].Value = se.ToString("0.00");

            rtb_Brife.Text = "单耳语频平均听阈：" + de.ToString("0.00") + "\n双耳高频平均听阈：" + se.ToString("0.00");
        }
        //小结
        private void bt_Brife_Click(object sender, EventArgs e)
        {
            if (str_RegID == "" || str_Count == "") return;
            if (dgv_tjjlmxb.Rows.Count == 0) return;

            rtb_Brife.Text = "";
            if (!object.Equals(null, dt_jbjlb)) dt_jbjlb.Rows.Clear();//先清空疾病记录表，然后重新绑定

            //处理特殊组合项目，例如一般情况，血压，乙肝两对半
            string str_zhxmbh = dgv_tjjlmxb.Rows[0].Cells["tjjlmxb_tjzhxm"].Value.ToString().Trim();
            string str_tjlx = dgv_tjjlmxb.Rows[0].Cells["tjjlmxb_tjlx"].Value.ToString().Trim();//体检类型
            DataTable dt_tj_hsb_hd = Disease.Get_TJ_HSB_HD(str_zhxmbh);//函数主档表
            if (dt_tj_hsb_hd.Rows.Count > 0)//在函数表中存在
            {
                int h = 1;
                string str_hsid = dt_tj_hsb_hd.Rows[0]["bh"].ToString().Trim();
                string str_hsmc = dt_tj_hsb_hd.Rows[0]["mc"].ToString().Trim();
                string str_xycldw = xtbiz.GetXtCsz("XyClDw");//1-以mmHg为单位；2-以kPa为单位

                string str_sgdzm = Disease.Get_TJ_HSB_XMDZ_DZM("身高");
                string str_tzdzm = Disease.Get_TJ_HSB_XMDZ_DZM("体重");
                string str_xydzm = Disease.Get_TJ_HSB_XMDZ_DZM("血压");
                decimal dec_sg = 0.00M;//身高
                decimal dec_tz = 0.00M;//体重
                decimal dec_zs = 0.00M;//比重指数
                string str_xyjg = "";
                try
                {
                    dec_sg = Convert.ToDecimal(dt_tjjlmxb.Select("tjxm='" + str_sgdzm + "'")[0]["jg"]);
                    dec_sg = dec_sg / 100;
                    dec_tz = Convert.ToDecimal(dt_tjjlmxb.Select("tjxm='" + str_tzdzm + "'")[0]["jg"]);
                    dec_zs = dec_tz / (dec_sg * dec_sg);

                }
                catch { }
                try
                {
                    str_xyjg = dt_tjjlmxb.Select("tjxm='" + str_xydzm + "'")[0]["jg"].ToString().Trim();//需和体重比分开赋值,当他们不在同一个组合项目下
                }
                catch { }

                if (dec_zs > 0)//身高体重比
                {
                    string str_tzzd = Disease.Get_pro_get_tzzs(dec_zs);
                    string str_keyword = str_tzzd.Split('|')[1];

                    if (str_keyword != "")//绑定疾病记录
                    {
                        DataTable dt = ywszbiz.Get_TJ_SUGGESTION(str_tjlx, str_keyword);
                        if (dt.Rows.Count > 0)
                        {
                            DataRow dr = dt_jbjlb.NewRow();
                            dr["jbbh"] = dt.Rows[0]["bh"].ToString().Trim();
                            dr["jbmc"] = dt.Rows[0]["keyword"].ToString().Trim();
                            dr["tjxmbh"] = str_sgdzm;
                            dt_jbjlb.Rows.Add(dr);
                        }
                    }
                    string text = "(" + h.ToString() + ")体重指数" + dec_zs.ToString("0.00") + "：" + str_tzzd.Split('|')[0] + "    ";
                    rtb_Brife.AppendText(text);

                    h++;
                }
                if (str_xyjg != "" && str_xyjg != "/")//血压
                {
                    decimal dec_ssy = 0.00M;//收缩压
                    decimal dec_szy = 0.00M;//舒张压
                    try
                    {
                        dec_ssy = Convert.ToDecimal(str_xyjg.Split('/')[0]);
                        dec_szy = Convert.ToDecimal(str_xyjg.Split('/')[1]);
                    }
                    catch { }
                    string str_xyzd = Disease.Get_pro_get_xyzs(dec_ssy, dec_szy, Convert.ToInt32(str_xycldw));
                    string str_keyword = str_xyzd.Split('|')[1];

                    if (str_keyword != "")//绑定疾病记录
                    {
                        DataTable dt = ywszbiz.Get_TJ_SUGGESTION(str_tjlx, str_keyword);
                        if (dt.Rows.Count > 0)
                        {
                            DataRow dr = dt_jbjlb.NewRow();
                            dr["jbbh"] = dt.Rows[0]["bh"].ToString().Trim();
                            dr["jbmc"] = dt.Rows[0]["keyword"].ToString().Trim();
                            dr["tjxmbh"] = str_xydzm;
                            dt_jbjlb.Rows.Add(dr);
                        }
                    }
                    string str = str_xyzd.Split('|')[0];
                    if (str == "") str = "血压正常";
                    string text = "(" + h.ToString() + ")血压" + str_xyjg + "：" + str + "    ";
                    rtb_Brife.AppendText(text);
                    h++;
                }
                //乙肝两对半
                if (str_hsmc == "乙肝两对半诊断功能")
                {
                    int k = 0;
                    string str_ckz = "";
                    foreach (DataGridViewRow dgr in dgv_tjjlmxb.Rows)//+,-,-,-,+
                    {
                        if (k > 4) break;//只取前面5项
                        if (dgr.Cells["tjjlmxb_sfyx"].Value.ToString().Trim() == "1")
                        {
                            str_ckz = str_ckz + "," + "+";
                        }
                        else
                        {
                            str_ckz = str_ckz + "," + "-";
                        }
                        k++;
                    }
                    str_ckz = str_ckz.Substring(1, str_ckz.Length - 1);
                    string str_ygzd = Disease.Get_TJ_HSB_DT(str_hsid, str_ckz);
                    string str_keyword = str_ygzd.Split('|')[1];

                    if (str_keyword != "")//绑定疾病记录
                    {
                        DataTable dt = ywszbiz.Get_TJ_SUGGESTION(str_tjlx, str_keyword);
                        if (dt.Rows.Count > 0)
                        {
                            DataRow dr = dt_jbjlb.NewRow();
                            dr["jbbh"] = dt.Rows[0]["bh"].ToString().Trim();
                            dr["jbmc"] = dt.Rows[0]["keyword"].ToString().Trim();
                            dr["tjxmbh"] = "";
                            dt_jbjlb.Rows.Add(dr);
                        }
                    }
                    string str = str_ygzd.Split('|')[0];
                    if (str != "")
                    {
                        string text = "(" + h.ToString() + ")" + str + "    ";
                        rtb_Brife.AppendText(text);
                    }
                    else
                    {
                        Get_Brife();
                    }
                    h++;
                }
            }
            else//不在函数表中存在
            {
                Get_Brife();
            }
            //若全部不需要进入小结,获取默认正常结果
            if (rtb_Brife.Text.Trim() == "")
            {
                //获取组合项目的
                rtb_Brife.Text = Disease.Get_ZHXM_ZCXJ(dgv_tjjlmxb.Rows[0].Cells["tjjlmxb_tjzhxm"].Value.ToString().Trim());
                if (rtb_Brife.Text.Trim() == "")//没有设置该项默认参考值
                {
                    rtb_Brife.Text = "未见明显异常";
                }
            }

            if (str_zhxmbh == "4801")//听力检测
            {
                Tljs();
            }
        }

        void Get_Brife()//获取小结内容
        {
            int i = 1;
            rtb_Brife.Text = "";
            //循环生成小结，疾病列表
            foreach (DataGridViewRow dgr in dgv_tjjlmxb.Rows)
            {
                string str_tjxm = dgr.Cells["tjjlmxb_tjxm"].Value.ToString().Trim();
                string str_tjzhxm = dgr.Cells["tjjlmxb_tjzhxm"].Value.ToString().Trim();//组合项目编号
                string str_mc = dgr.Cells["tjjlmxb_mc"].Value.ToString().Trim();
                string str_jg = dgr.Cells["tjjlmxb_jg"].Value.ToString().Trim();
                string str_sfyx = dgr.Cells["tjjlmxb_sfyx"].Value.ToString().Trim();
                string str_jrxj = dgr.Cells["tjjlmxb_jrxj"].Value.ToString().Trim();
                string str_mcjrxj = dgr.Cells["tjjlmxb_mcjrxj"].Value.ToString().Trim();
                string str_tjlx = dgr.Cells["tjjlmxb_tjlx"].Value.ToString().Trim();//体检类型
                string str_keyword = dgr.Cells["tjjlmxb_keyword"].Value.ToString().Trim();//对应诊断
                string str_ts = dgr.Cells["tjjlmxb_ts"].Value.ToString().Trim();//提示
                string text = "";//小结内容

                //2012-12-7*******************************************
                if (str_keyword == "" && str_sfyx == "1")
                {
                    str_keyword = ywszbiz.Get_tj_suggestion_jbbh(str_tjlx, str_jg);//当结果为阳性时，强制字符匹配诊断->名称不进入小结
                }
                if (str_keyword == "" && str_sfyx == "1")
                {
                    str_keyword = ywszbiz.Get_tj_suggestion_jbbh(str_tjlx, str_mc + str_jg);//当结果为阳性时，强制字符匹配诊断->名称进入小结
                }
                //2012-12-7********************************************

                if (str_jrxj == "1")
                {
                    if (str_mcjrxj == "1")
                    {
                        if (str_ts != "" && dgv_tjjlmxb.Tag.ToString().Trim() == "0")
                        {
                            text = str_mc + str_ts + "(" + str_jg + ")";
                        }
                        else
                        {
                            text = str_mc + str_jg;
                        }
                    }
                    else
                    {
                        text = str_jg;
                    }
                }
                if (text != "")
                {
                    text = "(" + i.ToString() + ")" + text + "    ";
                    rtb_Brife.AppendText(text);
                    i++;
                }

                if (str_keyword != "")//绑定疾病记录
                {
                    DataTable dt = ywszbiz.Get_TJ_SUGGESTION(str_tjlx, str_keyword);
                    if (dt.Rows.Count > 0)
                    {
                        DataRow dr = dt_jbjlb.NewRow();
                        dr["jbbh"] = dt.Rows[0]["bh"].ToString().Trim();
                        dr["jbmc"] = dt.Rows[0]["keyword"].ToString().Trim();
                        dr["tjxmbh"] = str_tjxm;
                        dt_jbjlb.Rows.Add(dr);
                    }
                }
            }
        }

        private void rtb_xj_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            bt_Brife_Click(null, null);
        }

        private void dgv_jbjlb_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex < 0) return;
            dgv_jbjlb.Rows.Remove(dgv_jbjlb.CurrentRow);
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 增加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (object.Equals(dt_tjjlmxb, null)) return;
            if (dgv_tjjlmxb.Rows.Count == 0) return;

            string str_tjlx = dgv_tjjlmxb.Rows[0].Cells["tjjlmxb_tjlx"].Value.ToString().Trim();//体检类型

            //诊断列表 诊断选择
            //Form_findzd frm = new Form_findzd(str_tjlx, "");
            //if (frm.ShowDialog() == DialogResult.OK)
            //{
            //    DataRow dr = dt_jbjlb.NewRow();
            //    dr["jbbh"] = frm.Str_bh;
            //    dr["jbmc"] = frm.Str_keyword;
            //    dt_jbjlb.Rows.Add(dr);
            //}
        }
        //删除体检明细
        private void bt_delete_Click(object sender, EventArgs e)
        {
            if (object.Equals(dt_tjjlmxb, null)) return;
            if (dgv_tjjlmxb.Rows.Count == 0) return;

            if (str_xzedit == "1")
            {
                if (str_User != Program.userid)
                {
                    MessageBox.Show("不能删除其他操作人员录入的数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    #region 日志记录
                    loginbiz.WriteLog(this.Name.Trim(), "【" + Program.username + "】" + "在电脑上尝试非法删除" + str_RegID + "的单项体检结果!IP：" + Program.hostip, Program.username);
                    #endregion
                    return;
                }
            }

            //体检记录明细表PE_Recorder
            registopr Recordropr = new registopr();
            Recordropr.str_Update_tj_tjjlb(str_RegID, str_Count, str_xh, str_zhxm);
            Recordropr.str_Update_tj_tjjlmxb(str_xh, str_zhxm);
            Recordropr.str_Delete_tj_jbjlb(str_RegID, str_Count, str_zhxm);
            Recordropr.Exec_ArryList();
            foreach (DataGridViewRow dgr in dgv_tjjlmxb.Rows)
            {
                dgr.Cells["tjjlmxb_ts"].Value = "";
                dgr.Cells["tjjlmxb_sfyx"].Value = "0";
                dgr.Cells["tjjlmxb_jrxj"].Value = "0";
                dgr.Cells["tjjlmxb_mcjrxj"].Value = "0";
                dgr.Cells["tjjlmxb_jg"].Value = dgr.Cells["tjjlmxb_zcjg"].Value;
                dgr.Cells["tjjlmxb_keyword"].Value = "";
            }
            rtb_Brife.Text = "";
            dgv_tjjlb.CurrentRow.DefaultCellStyle.BackColor = dgv_tjjlmxb.CurrentRow.DefaultCellStyle.BackColor;
            dgv_tjjlb.CurrentRow.Cells["isover"].Value = "0";
            #region 日志记录
            loginbiz.WriteLog(this.Name.Trim(), "【" + Program.username + "】" + "在电脑上删除了" + str_RegID + "的单项体检结果!IP：" + Program.hostip, Program.username);
            #endregion
            dt_jbjlb.Rows.Clear();//疾病记录表
            bt_edit_Click(null, null);//改成可编辑状态
        }

        private void dgv_tjjlb_SelectionChanged(object sender, EventArgs e)
        {
            if (dgv_tjjlb.SelectedRows.Count == 0) return;

            DataGridViewRow dgr = dgv_tjjlb.SelectedRows[0];
            index = dgr.Index;
            str_zhxm = dgr.Cells["zhxm"].Value.ToString().Trim();//组合项目编号
            str_xh = dgr.Cells["xh"].Value.ToString().Trim();//记录序号

            rtb_Brife.Text = "";
            DataTable dt = Disease.Get_TJ_TJJLB(str_RegID, str_Count, str_xh, str_zhxm);
            try
            {
                rtb_Brife.Text = dt.Rows[0]["xj"].ToString().Trim();
                str_User = dt.Rows[0]["czy"].ToString().Trim();//历史录入过的操作员-------------------------------------------------
                cmb_jcys.SelectedValue = dt.Rows[0]["jcys"].ToString().Trim();
                dtp_jcrq.Value = Convert.ToDateTime(dt.Rows[0]["jcrq"]);
            }
            catch
            {
            }

            JLMXB_DataBind(dgr);
            JBJLB_DataBind(str_RegID, str_Count, str_zhxm);//绑定疾病记录表

            string str_dxlrqxbkzks = xtbiz.GetXtCsz("dxlrqxbkzks").Trim(); //不控制录入权限的科室

            //结果录入权限控制
            string zxks = dgr.Cells["zxks"].Value.ToString().Trim();//执行科室
            if (Program.Usertype == "管理" || Program.Usertype == "总检医生" || Program.Usertype == "系统" || zxks == str_dxlrqxbkzks)
            {
                dgv_tjjlmxb.Columns["tjjlmxb_jg"].ReadOnly = false;
                //dgv_tjjlmxb.CellMouseDown += new DataGridViewCellMouseEventHandler(dgv_tjjlmxb_CellMouseDown);
                dgv_tjjlmxb.Columns["tjjlmxb_jg"].DefaultCellStyle.BackColor = Color.White;
            }
            else
            {
                if (Program.Branid == zxks)
                {
                    dgv_tjjlmxb.Columns["tjjlmxb_jg"].ReadOnly = false;
                    //dgv_tjjlmxb.CellMouseDown += new DataGridViewCellMouseEventHandler(dgv_tjjlmxb_CellMouseDown);
                    dgv_tjjlmxb.Columns["tjjlmxb_jg"].DefaultCellStyle.BackColor = Color.White;
                }
                else
                {
                    dgv_tjjlmxb.Columns["tjjlmxb_jg"].ReadOnly = true;
                    //dgv_tjjlmxb.CellMouseDown -= new DataGridViewCellMouseEventHandler(dgv_tjjlmxb_CellMouseDown);
                    dgv_tjjlmxb.Columns["tjjlmxb_jg"].DefaultCellStyle.BackColor = Color.FromArgb(220, 220, 220);

                }
            }
        }

        private void btn_wz_Click(object sender, EventArgs e)
        {
            //if (str_tjbh == "" || str_tjcs == "") return;
            //职业病问诊--
            //Form_zybwz frm = new Form_zybwz(str_RegID, str_Count);
            //if (frm.ShowDialog() == DialogResult.OK)
            //{

            //}
        }
    }
}
